package com.homer.gps.track.persist;

import com.j256.ormlite.field.DatabaseField;
import com.j256.ormlite.table.DatabaseTable;

@DatabaseTable(tableName = "places")
public class PlaceModel {

	// we use this field-name so we can query for places with a certain id
	public final static String ID_FIELD_NAME = "id";


	@DatabaseField(generatedId = true, columnName = ID_FIELD_NAME)
	private int id;
	@DatabaseField(canBeNull = false)
	private String name;
	@DatabaseField(canBeNull = false)
	private int type;

	@DatabaseField(canBeNull = true)
	private String street;
	@DatabaseField(canBeNull = true)
	private String house_number;
	@DatabaseField(canBeNull = true)
	private String postal_code;
	@DatabaseField(canBeNull = true)
	private String city;
	
	@DatabaseField(canBeNull = true)
	private String note;
	@DatabaseField(canBeNull = true)
	private String image_path;
	

	@DatabaseField(canBeNull = true)
	private double longitude;
	@DatabaseField(canBeNull = true)
	private double latitude;


	public PlaceModel(){
		// all persisted classes must define a no-arg constructor with at least package visibility
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getStreet() {
		return street;
	}

	public void setStreet(String street) {
		this.street = street;
	}

	public String getHouse_number() {
		return house_number;
	}

	public void setHouse_number(String house_number) {
		this.house_number = house_number;
	}

	public String getPostal_code() {
		return postal_code;
	}

	public void setPostal_code(String postal_code) {
		this.postal_code = postal_code;
	}

	public String getCity() {
		return city;
	}

	public void setCity(String city) {
		this.city = city;
	}

	public double getLongitude() {
		return longitude;
	}


	public void setLongitude(double longitude) {
		this.longitude = longitude;
	}


	public double getLatitude() {
		return latitude;
	}


	public void setLatitude(double latitude) {
		this.latitude = latitude;
	}

	public int getId() {
		return id;
	}

	public void setId(final int id) {
		this.id = id;
	}

	public final boolean hasId() {
		return 0 != this.id;
	}
	
	public int getType() {
		return type;
	}

	public void setType(int type) {
		this.type = type;
	}

	public String getNote() {
		return note;
	}

	public void setNote(String note) {
		this.note = note;
	}

	public String getImagePath() {
		return image_path;
	}

	public void setImagePath(String imagePath) {
		this.image_path = imagePath;
	}

	public CharSequence getParsedAddress() {
		String line1 = new String(), line2 = new String();
		
		line1 = line1.concat(this.street);
		if (line1.length() > 0 && (this.house_number != null && this.house_number.length() > 0))
		line1 = line1.concat(" ");
		line1 = line1.concat(this.house_number);

		line2 = line2.concat(this.postal_code);
		if (line2.length() > 0 && (this.city != null && this.city.length() > 0))
			line2 = line2.concat(" ");
		line2 = line2.concat(this.city);

		if (line2.length() > 0)
			return line1.concat(",\n").concat(line2);
		else
			return line1;
	}

}
